<?php

namespace addons\workteam\library;




class Gantt extends  \fast\Tree
{


    public function __construct($options = [])
    {
       parent::__construct($options);
    }

    /**
     *
     * 获取gantt数组
     * @param string $myid       要查询的ID
     * @param string $itemprefix 前缀
     * @return array
     */
    public function getLevelArray($myid, $itemprefix = '',$levels=0)
    {
        $childs = $this->getChild($myid);
        $data = [];
        $number = 1;
        $n=0;


        if ($childs) {
            $total = count($childs);
            foreach ($childs as $id => $value) {
                $j = $k = '';
                if ($number == $total) {
                    $j .= $this->icon[2];
                    $k = $itemprefix ? $this->nbsp : '';
                } else {
                    $j .= $this->icon[1];
                    $k = $itemprefix ? $this->icon[0] : '';
                }
                $spacer = $itemprefix ? $itemprefix . $j : '';
                if (isset($value['level']))
                    $value['diy_level']=$value['level'];//处理重要级别和gantt冲突问题

                $value['spacer'] = $spacer;
                $value['level'] = $levels;
                $data[$n] = $value;
                $n++;
                $childtemp=$this->getLevelArray($id, $itemprefix . $k . $this->nbsp,$levels+1);
                if ($childtemp){
                    $n += count($childtemp);
                    $data= array_merge_recursive($data,$childtemp);
                }

                $number++;

            }
        }

        return $data;
    }
}
